package operatori;

import main.Operator;

public final class Cat extends Operator {
	
	public double calcul(double aux1, double aux2) {
		return aux1 / aux2;
	}
		
	public static double Calcul(double aux1, double aux2) {
		return aux1 / aux2;
	}

	public double calculDerivata() {
		if(getfStang() == null || getfDrept() == null)
			System.exit(1);
		return Calcul(Minus.Calcul(Produs.Calcul(getfStang().calculDerivata(),getfDrept().calcul()),Produs.Calcul(getfStang().calcul(),getfDrept().calculDerivata())),Math.pow(getfDrept().calcul(),2));
	}

	public String derivare() {
		if(getfStang() == null || getfDrept() == null)
			System.exit(1);
		return concatTermeni("("+Minus.concatTermens(Produs.concatTermens(getfStang().derivare(),getfDrept().toString()),Produs.concatTermens(getfStang().toString(),getfDrept().derivare()))+")","(("+getfDrept().toString()+")^2)");
}

	public String concatTermeni(String aux1, String aux2) {
		String aux;
		if(aux1.compareTo("0") == 0 || aux2.compareTo("0") == 0)
			aux = aux1;
		else if(aux1.compareTo("0") == 0) aux = aux2;
		else if(aux2.compareTo("0") == 0) aux = aux1;
		else aux = aux1 + " / " + aux2;
		return aux;
	}
		
	public static String concatTermens(String aux1, String aux2) {
		String aux;
		if(aux1.compareTo("0") == 0 || aux2.compareTo("0") == 0)
			aux = aux1;
		else if(aux1.compareTo("0") == 0) aux = aux2;
		else if(aux2.compareTo("0") == 0) aux = aux1;
		else aux = aux1 + " / " + aux2;
		return aux;
	}

}
